package com.example.crt_dispatching_center.service.impl;

import com.example.crt_dispatching_center.entity.ElectricityCost;
import com.example.crt_dispatching_center.mapper.CostMapper;
import com.example.crt_dispatching_center.service.CostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CostServiceImpl implements CostService {
    @Autowired
    private CostMapper costMapper;

    @Override
    public Map<String, List<?>> getCost() {
        LocalDate endDate = LocalDate.now();
        LocalDate startDate = endDate.minusDays(7);
        List<ElectricityCost> elcostform=costMapper.findByDateBetween(startDate, endDate);
        List<Float> elcost=new ArrayList<>();
        for(ElectricityCost electricityCost:elcostform)
        {
            Float cost=electricityCost.getCost();
            elcost.add(cost);
        }
        Map<String, List<?>> map = new HashMap<>();
        map.put("elcost",elcost);
        return map;
    }
}
